package cn.springcloud.fix.common.core.base;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Builder
@ToString
@Accessors(chain = true)
@AllArgsConstructor
public class R<T> implements Serializable {

    private int code;

    private T data;

    private String message;

    private String debugMsg;

   /* public R() {
    }

    public R(T data) {
        this.data = data;
    }

    public R(T data, String message) {
        this.data = data;
        this.message = message;
    }

    public R(int code, String msg, T data) {
        this.code = code;
        this.message = msg;
        this.data = data;
    }

    private R(int code, String msg) {
        this.code = code;
        this.message = msg;
    }

    private R(int code, String msg, String debugMsg) {
        this.message = msg;
        this.code = code;
        this.debugMsg = debugMsg;
    }*/

    private R(int code, String msg, T data, String debugMsg) {
        this.message = msg;
        this.code = code;
        this.data = data;
        this.debugMsg = debugMsg;
    }

    public static <T> R<T> build(int code, String msg, T data, String debugMsg) {
        return new R<>(code, msg, data, debugMsg);
    }

    public static <T> R<T> SUCCESS() {
        return build(0, "SUCCESS", null, null);
    }

    public static <T> R<T> SUCCESS(T data) {
        return build(0, "SUCCESS", data, null);
    }

    public static <T> R<T> SUCCESS(String msg) {
        return build(0, msg, null, null);
    }

    public static <T> R<T> ERROR() {
        return build(-1, "ERROR", null, null);
    }

    public static <T> R<T> ERROR(String msg) {
        return build(-1, msg, null, null);
    }

    public static <T> R<T> ERROR(Throwable e) {
        return build(-1, e.getMessage(), null, null);
    }

    public static <T> R<T> ERROR(int code, String msg) {
        return build(code, msg, null, null);
    }

    public static <T> R<T> ERROR(String msg, String debugMsg) {
        return build(-1, msg, null, debugMsg);
    }
}
